<template>
  <el-dialog
      title="设置样板工地"
      :visible.sync="visible"
      :close-on-click-modal="false"
      width="500px"
  >
    <el-table height="500px" :data="bottomList" :border="true" key="">
      <el-table-column label="样板" prop="is_top" align="center" width="55">
        <template #default="scope">
          <el-checkbox v-model="scope.row.is_top" true-label="1" false-label="0"></el-checkbox>
        </template>
      </el-table-column>
      <el-table-column label=" 工地名称
          " prop="name" align="center">
      </el-table-column>
    </el-table>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="handleSave">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>

import {videoRequest} from "@/utils/http/request";

export default {
  name: "UploadVideoDialog",
  emits: ['save'],
  data() {
    return {
      visible: false,
      loading: false,
      bottomList: []
    }
  },
  methods: {
    openDialog(bottomList) {
      this.bottomList = bottomList.filter(item => item.is_true === '1').map(item => {
        return {...item}
      })
      this.visible = true
    },
    handleSave() {
      const topList = this.bottomList.filter(item => item.is_top === '1').map(item => {
        return {
          ID: item.ID,
          is_top: '1'
        }
      })
      videoRequest.setModelEdit({datalist: topList}).then(res => {
        const {code, msg} = res
        if (code === '01') {
          this.$message.success(msg)
          this.$emit('save')
          this.visible = false
        } else {
          this.$message.error(msg)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../../../assets/style/base.scss";

</style>
